package com.itheima.controller;

import com.itheima.admin.dishpojo.Dish;
import com.itheima.client.dishpojo.vo.DishSetmealVo;
import com.itheima.client.dishpojo.vo.SetmealVo;
import com.itheima.common.JsonResult;
import com.itheima.service.ClientSetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wuzhiyong
 */
@RestController
@RequestMapping(value = "/setmeal")
public class ClientSetmealController {
    @Autowired
    private ClientSetmealService clientSetmealService;

    /**
     * 菜品详情
     * @param setmealId setmealId
     * @return JsonResult
     */
    @GetMapping(value = "/dish/{setmealId}")
    public JsonResult<List<DishSetmealVo>> setmealDish(@PathVariable(value = "setmealId") String setmealId){
        List<DishSetmealVo> dishes = clientSetmealService.getBySetmealId(setmealId);
        if (dishes!=null){
            return JsonResult.success(dishes, null);
        }
        return JsonResult.error(null);
    }

    /**
     * 套餐列表
     * @param categoryId categoryId
     * @param status status
     * @return JsonResult
     */
    @GetMapping(value = "/list")
    public JsonResult<List<SetmealVo>> detmealLish(@RequestParam(value = "categoryId",required = false) String categoryId, @RequestParam(value = "status",required = false) Integer status){
        List<SetmealVo> setmealVos = clientSetmealService.getSetmeal(categoryId, status);
        if (setmealVos!=null){
            return JsonResult.success(setmealVos, null);
        }
        return JsonResult.error(null);
    }
}

